#ifndef _ERP_GISMAP_GLABLE_CONFIG_H_
#define _ERP_GISMAP_GLABLE_CONFIG_H_

#include <string>
#include <vector>

namespace erp
{
namespace gis
{
namespace ao
{


class CProxy
{
public:
	CProxy() {}
	CProxy(uint32_t dwProxyPort, const std::string& strProxy)
	{
		m_dwProxyPort = dwProxyPort;
		m_strProxy    = strProxy;
	}
	uint32_t GetProxyPort() const
	{
		return m_dwProxyPort;
	}
	const std::string& GetProxy() const
	{
		return m_strProxy;
	}

private:
	uint32_t    m_dwProxyPort;
	std::string m_strProxy;
};

class CGisMapConfigInfo
{
public:
	CGisMapConfigInfo() {}
	void Init(
		 bool bNeedCheck,
		 uint32_t dwTimeout,
		 const std::string& strUrl,
		 const std::vector<CProxy>& vecProxy)
	{
		m_bNeedCheck = bNeedCheck;
		m_dwTimeout  = dwTimeout;
		m_strUrl     = strUrl;
		m_vecProxy   = vecProxy;
		if (!m_vecProxy.empty())
			m_oCurrentProxy = m_vecProxy[0];
	}
	
	void SetCurrentProxy(const CProxy& oProxy)
	{
		m_oCurrentProxy = oProxy;
	}
	
	bool IsNeedCheckData()
	{
		return m_bNeedCheck;
	}
	uint32_t GetTimeout()
	{
		return m_dwTimeout;
	}
	const std::string& GetUrl() const
	{
		return m_strUrl;
	}
	const CProxy& GetCurrentProxy() const
	{
		return m_oCurrentProxy;
	}
	const std::vector<CProxy>& GetProxy() const
	{
		return m_vecProxy;
	}
	
private:
	bool                 m_bNeedCheck;
	uint32_t             m_dwTimeout;
	std::string          m_strUrl;
	CProxy               m_oCurrentProxy;
	std::vector<CProxy>  m_vecProxy;
};


class CGisMapGlobalConfig {
public:
	static uint32_t  GetSwitchProxyThreshold();
	static void SetSwitchProxyThreshold(uint32_t dwSwitchProxyThreshold);
	
	// all unrequired.
	static int SetSosoConfig(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchSosoProxy();

	static int SetSoso2Config(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchSoso2Proxy();

	static int SetBaiduConfig(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchBaiduProxy();

	static int SetGoogleConfig(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchGoogleProxy();

	static int SetAliyunConfig(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchAliyunProxy();

	static int SetGaodeConfig(
				bool bNeedCheck,
				uint32_t dwTimeout,
				const std::string& strUrl,
				const std::string& strProxyList);
	static void SwitchGaodeProxy();

	static uint32_t GetSosoTimeout();
	static uint32_t GetSosoProxyPort();
	static bool GetSosoCheckDataSwitch();
	static const std::string& GetSosoUrl();
	static const std::string& GetSosoProxy();

	static uint32_t GetSoso2Timeout();
	static uint32_t GetSoso2ProxyPort();
	static bool GetSoso2CheckDataSwitch();
	static const std::string& GetSoso2Url();
	static const std::string& GetSoso2Proxy();

	static uint32_t GetBaiduTimeout();
	static uint32_t GetBaiduProxyPort();
	static bool GetBaiduCheckDataSwitch();
	static const std::string& GetBaiduUrl();
	static const std::string& GetBaiduProxy();

	static uint32_t GetGoogleTimeout();
	static uint32_t GetGoogleProxyPort();
	static bool GetGoogleCheckDataSwitch();
	static const std::string& GetGoogleUrl();
	static const std::string& GetGoogleProxy();

	static uint32_t GetAliyunTimeout();
	static uint32_t GetAliyunProxyPort();
	static bool GetAliyunCheckDataSwitch();
	static const std::string& GetAliyunUrl();
	static const std::string& GetAliyunProxy();

	static uint32_t GetGaodeTimeout();
	static uint32_t GetGaodeProxyPort();
	static bool GetGaodeCheckDataSwitch();
	static const std::string& GetGaodeUrl();
	static const std::string& GetGaodeProxy();

private:
	static int ParseProxy(
		       const std::string& strProxyList, 
		       std::vector<CProxy>& vecProxy);
	
	static int SetConfig(
		        bool bNeedCheck,
		        uint32_t dwTimeout,
		        const std::string& strUrl,
		        const std::string& strProxyList,
		        CGisMapConfigInfo& oGisMapConfigInfo);

private:
	static CGisMapConfigInfo m_oSosoConfig;
	static CGisMapConfigInfo m_oSoso2Config;
	static CGisMapConfigInfo m_oBaiduConfig;
	static CGisMapConfigInfo m_oGoogleConfig;
	static CGisMapConfigInfo m_oAliyunConfig;
	static CGisMapConfigInfo m_oGaodeConfig;
	
	static uint32_t m_dwSwitchProxyThreshold;
};
}
}
}

#endif /*_ERP_GISMAP_GLABLE_CONFIG_H_*/

